<?php

namespace app\api\controller\mall;

use app\api\controller\AuthBase;
use app\common\lib\Show;
use app\common\business\Cart;

/**
 * 初始化购物车
 * Class Init
 * @package app\api\controller\mall
 */
class Init extends AuthBase {

    /**
     * 获取购物车数量
     * @return \think\response\Json
     */
    public function index() {
        if (!$this->request->isPost()) {
            return Show::error();
        }

        $count = (new Cart())->getCount($this->userId);
        $result = [
            'cart_num' => $count,
        ];
        return Show::success($result);
    }
}